#ifndef COLLECTDATASAVE_H
#define COLLECTDATASAVE_H

#include <QObject>
#include "itemdata.h"
#include "savedatatool.h"


class CollectDataSave : public QObject
{
    Q_OBJECT

    Q_PROPERTY(int id READ getCurrid NOTIFY valuechang )
    Q_PROPERTY(QString item READ getItem NOTIFY valuechang )
    Q_PROPERTY(QString product READ getProduct NOTIFY valuechang )
    Q_PROPERTY(int samplenuber READ getNuber WRITE setNuber NOTIFY valuechang )
    Q_PROPERTY(double tolerance READ getTolerance WRITE  setTolerance NOTIFY valuechang )
    Q_PROPERTY(QString datetime READ getDate NOTIFY valuechang )
    Q_PROPERTY(double value READ getValue WRITE setValue NOTIFY valuechang)


public:
    explicit CollectDataSave(QObject *parent = nullptr);
    void  inits();
    QList<QObject*> items;

    //当前id
    int currid=1;
    int getCurrid(){return currid;}
    //同编号测试次数
    int itemindex=0;

    //最后一次测试数据
    ItemData *lastData=nullptr;

    //测量项目名
    QString ItemType;
    QString getItem(){return ItemType;}
    //产品名
    QString product;
    QString getProduct(){return product;}

    //样品编号
    int sampleNuber;
    int getNuber(){return sampleNuber;}
    void setNuber(int i){ sampleNuber=i;}

    //容差
    double tolerance;
    double getTolerance(){return tolerance;}
    void setTolerance(double i){ tolerance=i;}
    //是否在容差内
    bool islrance=false;

    //目期
    QString Datestr;
    QString getDate(){return Datestr;}
    void resetDate();

    //测量值
    double Value=0;
    double getValue(){return Value;}
    void setValue(double i){ Value=i;}

    //精度
    int precision=3;
    //交割时间
    int delivery=0;

    //保存数路径
    QString savepath;

    //配置路径
    QString configpath;




    void readconfig();
    void initview();
    void writeconfig();

    void saveDatas();

signals:
    void valuechang();
    void changMessage(QString msg);
    void showDatas(QString msg);
private :
    SaveDataTool dataTool;

public slots:
    void contDatas();
    void nextid();
    void nextNumber();
    void save();
    void next();
    void chengvalue();

    void selectNumber(int num);

    QList<QObject*> getIitems();

};

#endif // COLLECTDATASAVE_H
